Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackathon 5th No.63 PhyCRNet: Physics-informed Convolutional-Recurrent Network for Solving Spatiotemporal PDEs #557

Closed
wants to merge 8 commits into from

Conversation

co63oc
Copy link
Contributor

@co63oc co63oc commented Sep 28, 2023

PR types

Others

PR changes

Others

Describe

PaddlePaddle/Paddle#57262
image

Loss精度

- torch paddle
loss 18.55 17.86

运行 200 次截图
torch
image
paddle
image

@paddle-bot
Copy link

paddle-bot bot commented Sep 28, 2023

Thanks for your contribution!

@HydrogenSulfate
Copy link
Collaborator

黑客松的赛题有要求需要基于PaddleScience套件进行开发,
image

@co63oc
Copy link
Contributor Author

co63oc commented Sep 29, 2023

黑客松的赛题有要求需要基于PaddleScience套件进行开发

图片
这个模型一个epoch多次调用model.forward,传递不同initial_state,下一次的initial_state是上一次计算返回,现在Solver接口是每个epoch调用一次forward,不知道这是要用什么api转换

@HydrogenSulfate
Copy link
Collaborator

HydrogenSulfate commented Oct 1, 2023

黑客松的赛题有要求需要基于PaddleScience套件进行开发

图片 这个模型一个epoch多次调用model.forward,传递不同initial_state,下一次的initial_state是上一次计算返回,现在Solver接口是每个epoch调用一次forward,不知道这是要用什么api转换

  1. 可以把内层的for循环逻辑放到 Arch.output_transform 里,然后loss多次backward等价于把这些loss保存下来,求和后做一次backward

@co63oc
Copy link
Contributor Author

co63oc commented Oct 14, 2023

更新使用 PaddleScience套件,增加ppsci.arch.PhyCRNet

@co63oc
Copy link
Contributor Author

co63oc commented Oct 14, 2023

没有使用ppsci.utils.load_mat_file,ppsci.utils.load_mat_file中会对数据reshape,没有明白怎么要对数据reshape
image

Copy link
Contributor

@wangguan1995 wangguan1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to align with paper


## 5. 结果展示

PhyCRNet 案例针对 epoch=200 和 learning\_rate=1e-4 的参数配置进行了实验,结果返回Loss为 17.86。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compute the error

error = frobenius_norm(np.array(ten_pred)-np.array(ten_true)) / frobenius_norm(
    np.array(ten_true))

print('The predicted error is: ', error)

u_pred = output[:-1, 0, :, :].detach().cpu().numpy()
u_pred = np.swapaxes(u_pred, 1, 2) # [h,w] = [y,x]
u_true = truth[:, 0, :, :]

t_true = np.linspace(0, 2, 1001)
t_pred = np.linspace(0, 2, time_steps)

plt.plot(t_pred, u_pred[:, 32, 32], label='x=32, y=32, CRL')
plt.plot(t_true, u_true[:, 32, 32], '--', label='x=32, y=32, Ref.')
plt.xlabel('t')
plt.ylabel('u')
plt.xlim(0, 2)
plt.legend()
plt.savefig(fig_save_path + "x=32,y=32.png")
plt.close("all")
# plt.show()

# plot train loss
plt.figure()
plt.plot(train_loss, label = 'train loss')
plt.yscale('log')
plt.legend()
plt.savefig(fig_save_path + 'train loss.png', dpi = 300)

科学计算类论文复现,更关注 物理error和最后的物理场效果,参考原文代码复现error和对比图
(可以从checkpoint加载模型直接eval,不需要重新训练)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加变量graph,设置为True生成error,对比图
image
image

Copy link
Contributor

@wangguan1995 wangguan1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need a-RMSE plot for t in [0,4]

# initialize logger
logger.init_logger("ppsci", f"{OUTPUT_DIR}/train.log", "info")
# set training hyper-parameters
EPOCHS = 200 if not args.epochs else args.epochs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2000

return result_dict["loss"]


def output_graph(model, input_dataset, fig_save_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

论文指标以a-RMSE形式评估
image

@@ -0,0 +1,273 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FN_2d_solver_[HighOrder].py
FitzHugh- Nagumo RD 方程数据生成代码需要补齐

np.array(ten_pred) - np.array(ten_true)
) / functions.frobenius_norm(np.array(ten_true))

print("The predicted error is: ", error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error要求达到:源码,论文(1e-3)取较大值

--8<--
```

### 3.7 模型训练与评估
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照
image
翻译,并介绍误差


self.input_channels = input_channels
self.hidden_channels = hidden_channels
self.hidden_kernel_size = 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3是怎么来的?

self.input_kernel_size = input_kernel_size
self.input_stride = input_stride
self.input_padding = input_padding
self.num_features = 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4是怎么来的?

class loss_generator(nn.Layer):
"""Loss generator for physics loss"""

def __init__(self, dt=(10.0 / 200), dx=(20.0 / 128)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认值删掉

if __name__ == "__main__":
# grid size
M, N = 128, 128
n_simu_steps = 30000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

40000

layer_state_dict = paddle.load("output/phycrnet.pdparams")
model.set_state_dict(layer_state_dict)
model.register_output_transform(None)
output_graph(model, input_dict_val, fig_save_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input_dict_val进行修改,尝试完成时间变量t,从0s到4s的u_predict和u_true的对比,以及a-RMSE计算

@co63oc
Copy link
Contributor Author

co63oc commented Nov 6, 2023

暂时关闭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants